/*
 * Copyright 2010 J Patrick Davenport
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package v4view.web;

import java.io.IOException;

/**
 * Represents the form element in the HTML DOM.
 * @author J Patrick Davenport
 *
 */
public class Form extends ChildbearingPageElement implements ICoreAttributes, ILanguageAttributes<Form>, IMouseEvents<Form>, IKeyboardEvents<Form> {
	private static final String	NAME_KEY			= "name";
	private static final String	METHOD_KEY			= "method";
	private static final String	ENCTYPE_KEY			= "enctype";
	private static final String	ACCEPT_CHARSET_KEY	= "accept-charset";
	private static final String	ACCEPT_KEY			= "accept";
	private static final String	ACTION_KEY			= "action";
	private static final String	ONRESET_KEY			= "onreset";
	private static final String	ONSUBMIT_KEY		= "onsubmit";
	private static final String	FORM_KEY			= "form";

	private boolean				addContext;
	{
		this.setTag(FORM_KEY);
		this.setSupportsAttributes(true);
	}

	public Form() {

	}

	public Form(final boolean _addContext) {
		this.addContext = _addContext;
	}

	public String getOnSubmit() {
		return this.getAttributeValue(ONSUBMIT_KEY);
	}

	public Form setOnSubmit(final String _value) {
		return (Form) this.setAttribute(ONSUBMIT_KEY, _value);
	}

	public String getOnReset() {
		return this.getAttributeValue(ONRESET_KEY);
	}

	public Form setOnReset(final String _value) {
		return (Form) this.setAttribute(ONRESET_KEY, _value);
	}

	public String getAction() {
		return this.getAttribute(ACTION_KEY).getValue();

	}

	public String getAccept() {
		return this.getAttribute(ACCEPT_KEY).getValue();

	}

	public String getAcceptCharset() {
		return this.getAttribute(ACCEPT_CHARSET_KEY).getValue();

	}

	public String getEnctype() {
		return this.getAttribute(ENCTYPE_KEY).getValue();

	}

	public String getMethod() {
		return this.getAttribute(METHOD_KEY).getValue();

	}

	public String getName() {
		return this.getAttribute(NAME_KEY).getValue();

	}

	public Form setAction(final String _value) {
		this.setAttribute(ACTION_KEY, _value);
		return this;
	}

	public Form setAccept(final String _value) {
		this.setAttribute(ACCEPT_KEY, _value);
		return this;
	}

	public Form setAcceptCharset(final String _value) {
		this.setAttribute(ACCEPT_CHARSET_KEY, _value);
		return this;
	}

	public Form setEnctype(final String _value) {
		this.setAttribute(ENCTYPE_KEY, _value);
		return this;
	}

	public Form setMethod(final String _value) {
		this.setAttribute(METHOD_KEY, _value);
		return this;
	}

	public Form setName(final String _value) {
		this.setAttribute(NAME_KEY, _value);
		return this;
	}

	@Override
	public String getCssClass() {
		return this.getAttributeValue(CSS_CLASS_KEY);
	}

	@Override
	public String getId() {
		return this.getAttributeValue(ID_KEY);
	}

	@Override
	public String getStyle() {
		return this.getAttributeValue(STYLE_KEY);
	}

	@Override
	public String getTitle() {
		return this.getAttributeValue(TITLE_KEY);
	}

	@Override
	public Form setCssClass(final String _value) {
		return (Form) this.setAttribute(CSS_CLASS_KEY, _value);
	}

	@Override
	public Form setId(final String _value) {
		return (Form) this.setAttribute(ID_KEY, _value);
	}

	@Override
	public Form setStyle(final String _value) {
		return (Form) this.setAttribute(STYLE_KEY, _value);
	}

	@Override
	public Form setTitle(final String _value) {
		return (Form) this.setAttribute(TITLE_KEY, _value);
	}

	@Override
	public Form setOnKeyDown(final String _scriptlet) {
		return (Form) this.setAttribute(KEY_DOWN_EVENT_KEY, _scriptlet);
	}

	@Override
	public Form setOnKeyPress(final String _scriptlet) {
		return (Form) this.setAttribute(KEY_PRESS_EVENT_KEY, _scriptlet);
	}

	@Override
	public Form setOnKeyUp(final String _scriptlet) {
		return (Form) this.setAttribute(KEY_UP_EVENT_KEY, _scriptlet);
	}

	@Override
	public String getOnKeyDown() {
		return this.getAttributeValue(KEY_DOWN_EVENT_KEY);
	}

	@Override
	public String getOnKeyPress() {
		return this.getAttributeValue(KEY_PRESS_EVENT_KEY);
	}

	@Override
	public String getOnKeyUp() {
		return this.getAttributeValue(KEY_UP_EVENT_KEY);
	}

	@Override
	public Form setDir(final String _value) {
		return (Form) this.setAttribute(DIR_KEY, _value);
	}

	@Override
	public Form setLang(final String _lang) {
		return (Form) this.setAttribute(LANG_KEY, _lang);
	}

	@Override
	public Form setXmlLang(final String _xmlLang) {
		return (Form) this.setAttribute(XML_LANG_KEY, _xmlLang);
	}

	@Override
	public String getDir() {
		return this.getAttributeValue(DIR_KEY);
	}

	@Override
	public String getLang() {
		return this.getAttributeValue(LANG_KEY);
	}

	@Override
	public String getXmlLang() {
		return this.getAttributeValue(XML_LANG_KEY);
	}

	@Override
	public Form setOnClick(final String _scriptlet) {
		return (Form) this.setAttribute(ON_MOUSECLICK_EVENT_KEY, _scriptlet);
	}

	@Override
	public Form setOnDblClick(final String _scriptlet) {
		return (Form) this.setAttribute(ON_MOUSEDBLCLICK_EVENT_KEY, _scriptlet);
	}

	@Override
	public Form setOnMouseDown(final String _scriptlet) {
		return (Form) this.setAttribute(ON_MOUSEDOWN_EVENT_KEY, _scriptlet);
	}

	@Override
	public Form setOnMouseMove(final String _scriptlet) {
		return (Form) this.setAttribute(ON_MOUSEMOVE_EVENT_KEY, _scriptlet);
	}

	@Override
	public Form setMouseOut(final String _scriptlet) {
		return (Form) this.setAttribute(ON_MOUSEOUT_EVENT_KEY, _scriptlet);
	}

	@Override
	public Form setMouseOver(final String _scriptlet) {
		return (Form) this.setAttribute(ON_MOUSEOVER_EVENT_KEY, _scriptlet);
	}

	@Override
	public Form setMouseUp(final String _scriptlet) {
		return (Form) this.setAttribute(ON_MOUSEUP_EVENT_KEY, _scriptlet);
	}

	@Override
	public String getOnClick() {
		return this.getAttributeValue(ON_MOUSECLICK_EVENT_KEY);
	}

	@Override
	public String getOnDblClick() {
		return this.getAttributeValue(ON_MOUSEDBLCLICK_EVENT_KEY);
	}

	@Override
	public String getOnMouseDown() {
		return this.getAttributeValue(ON_MOUSEDOWN_EVENT_KEY);
	}

	@Override
	public String getOnMouseMove() {
		return this.getAttributeValue(ON_MOUSEMOVE_EVENT_KEY);
	}

	@Override
	public String getMouseOut() {
		return this.getAttributeValue(ON_MOUSEOUT_EVENT_KEY);
	}

	@Override
	public String getMouseOver() {
		return this.getAttributeValue(ON_MOUSEOVER_EVENT_KEY);
	}

	@Override
	public String getMouseUp() {
		return this.getAttributeValue(ON_MOUSEUP_EVENT_KEY);
	}

	@Override
	public void render() throws IOException {
		if (this.addContext) {
			this.setAction(this.getContextPath() + this.getAction());
		}

		super.render();
	}
}
